package cn.hanyx.coder.design.pattern.behavioral.chain.demo02;

import java.util.ArrayList;
import java.util.List;

/**
 * HandlerChain
 *
 * @author hanyx
 * @date 2020/06/05
 */
public class HandlerChain {

    private List<IHandler> handlerList = new ArrayList<>();

    public void addHandler(IHandler handler) {
        handlerList.add(handler);
    }

    /**
     * 循环执行各个处理器
     */
    public void handle() {
        for (IHandler handle : handlerList) {
            if (handle.handle()) {
                break;
            }
        }
    }
}
